package com.zq.blog_serve.controller.flowable;

import com.zq.blog_serve.common.AjaxResult;
import com.zq.blog_serve.entity.condition.BaseCondition;
import com.zq.blog_serve.entity.flowable.ProcessDefinitionDTO;
import com.zq.blog_serve.service.flowable.ProcessDefinitionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("processDefine")
public class ProcessDefineController {

    @Autowired
    ProcessDefinitionService processDefinitionService;


    // 获取所有流程定义
    @PostMapping("pageList")
    public AjaxResult pageList(@RequestBody BaseCondition condition) {
        return AjaxResult.success(processDefinitionService.getProcessDefinitions(condition));
    }

    // 获取单个流程定义
    @GetMapping("/{id}")
    public AjaxResult getProcessDefinition(@PathVariable String id) {
        return AjaxResult.success(processDefinitionService.getProcessDefinitionById(id));
    }

    // 部署流程定义（修改后的接口）
    @PostMapping("/deploy")
    public AjaxResult deployProcessDefinition(@RequestBody ProcessDefinitionDTO dto) {
        return AjaxResult.success(processDefinitionService.deployProcessDefinition(dto.getName(), dto.getXml()));
    }

    // 挂起流程定义
    @PutMapping("/{id}/suspend")
    public void suspendProcessDefinition(@PathVariable String id) {
        processDefinitionService.suspendProcessDefinition(id);
    }

    // 激活流程定义
    @PutMapping("/{id}/activate")
    public void activateProcessDefinition(@PathVariable String id) {
        processDefinitionService.activateProcessDefinition(id);
    }

    // 删除部署
    @DeleteMapping("/deployments/{deploymentId}")
    public void deleteDeployment(@PathVariable String deploymentId) {
        processDefinitionService.deleteDeployment(deploymentId);
    }

}
